﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using mamnontuoitho7.AppCode;
using System.Security.Cryptography;
using System.Data;

namespace mamnontuoitho7.module
{
    public partial class LoginForm : System.Web.UI.UserControl
    {
        Member _member = new Member();
        Home _home = new Home();
        private Parent _parent = new Parent();
        private mamnontuoitho7.AppCode.Contact _contact = new mamnontuoitho7.AppCode.Contact();
        private KidWall _kidWall = new KidWall();

        protected General _general = new General();
        protected Conversation _conversation = new Conversation();

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                imgMember.ImageUrl = "../images/avatar/teacher_parents/" + (Session["avatar"].ToString() != "" ? Session["avatar"].ToString() : ConstantClass._memberDefaultAvatar);

                if (!IsPostBack)
                {
                    if (Session["username"].ToString() != "")
                    {
                        loginstart.Visible = false;
                        loginsuccess.Visible = true;

                        if (Session["role"].ToString() == "4")//phu huynh
                        {
                            if (_parent.CheckParentAvailability(Session["memberID"].ToString()) == "2")
                            {
                                Session["conversationParent"] = _conversation.TotalUnanswerConversationOfOneParent(Session["memberID"].ToString()).GetValueOrDefault().ToString();
                                Session["noticeParent"] = _conversation.Count3DayNotice("3", Session["strClassID"].ToString()).GetValueOrDefault().ToString();
                                Session["wallKid"] = _kidWall.TotalUnseenWallOfKids(Session["memberID"].ToString()).GetValueOrDefault().ToString();
                            }
                            else
                            {
                                Session["conversationParent"] = "0";
                                Session["noticeParent"] = "0";
                                Session["wallKid"] = "0";
                            }
                        }
                        if (Session["role"].ToString() == "3")
                        {
                            Session["conversationTeacher"] = _conversation.TotalUnanswerConversationOfOneClass(Session["classID"].ToString()).GetValueOrDefault().ToString();
                        }
                        if (Session["role"].ToString() == "2" || Session["role"].ToString() == "6" || Session["role"].ToString() == "7")
                        {
                            Session["newContactNumber"] = _contact.TotalUnaswerOfContact().GetValueOrDefault().ToString();
                        }
                    }
                    else
                    {
                        loginstart.Visible = true;
                        loginsuccess.Visible = false;
                    }
                    
                    Session["Common_currentPageLink"] = HttpContext.Current.Request.Url.AbsoluteUri;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Response.Redirect(ConstantClass._errorPage);
            }
        }
    }
}